home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / jx4nt125.zip / UNIASCII.C < prev    next >
C/C++ Source or Header  |  1994-05-20  |  3KB  |  97 lines

  1. /* uniblock.c ... convert Forth 1024-byte BLOCK files to Forth 1024-widechar BLOCK files.
  2.  * Copyright (C) 1993 by
  3.  * jack j. woehr, p.o. box 51, golden, colorado 80402-0051
  4.  * jax@well.sf.ca.us JAX on GEnie 72203.1320@compuserve.com
  5.  * SYSOP, RealTime Control & Forth Board [RCFB] (303) 278-0364
  6.  
  7. /*
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2 of the License, or
  11.  * (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details. (doc\license.txt)
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; if not, write to the Free Software
  20.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23. #include <windows.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26.  
  27. #define USAGE    "Usage: %s sourcefile destfile\n (or %s /? for help)\n", argv[0], argv[0]
  28.  
  29. SECURITY_ATTRIBUTES myAttrib;
  30. DWORD numRead;
  31. DWORD numWritten;
  32. char    buff[1024];
  33. char    fubb[2048];
  34.  
  35. int main (int argc, char *argv[]) {
  36.  
  37.     DWORD    i;
  38.     int    j = 0;
  39.  
  40.     DWORD temp = 0;
  41.  
  42.     HANDLE ifh;
  43.     HANDLE ofh;
  44.  
  45.     if (argc > 3) {
  46.         fprintf (stderr, USAGE);
  47.         return 99;
  48.     }
  49.  
  50.     if    (argc == 2)
  51.         if (!(strcmp (argv[1], "/?"))) {
  52.             fprintf (stderr, USAGE);
  53.             fprintf (stderr, "%s\n%s\n%s\n",
  54.                 "Converts the Unicode file specified by the sourcefile argument",
  55.                 "to an ASCII file one-half the size.",
  56.                 "Creates destination file or silently overwrites existing file of same name.");
  57.             return    99;
  58.             }
  59.  
  60.     if (argc < 3) {
  61.         fprintf (stderr, USAGE);
  62.         return 99;
  63.     }
  64.  
  65.     myAttrib.nLength = sizeof (myAttrib);
  66.     myAttrib.lpSecurityDescriptor = NULL;
  67.     myAttrib.bInheritHandle = TRUE;
  68.  
  69.     if    (INVALID_HANDLE_VALUE == 
  70.             (ifh = CreateFile (argv[1], GENERIC_READ, 0, &myAttrib, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0)))
  71.         {
  72.         temp = GetLastError();
  73.         fprintf (stderr, "Couldn't open source file.\n");
  74.         return temp;
  75.         }
  76.  
  77.     if    (INVALID_HANDLE_VALUE == 
  78.             (ofh = CreateFile (argv[2], GENERIC_WRITE, 0, &myAttrib, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,0)))
  79.         {
  80.         temp = GetLastError();
  81.         fprintf (stderr, "Couldn't open destination file.\n");
  82.         return temp;
  83.         }
  84.  
  85.     while (ReadFile (ifh, &fubb, 2048, &numRead, 0)) {
  86.         if (numRead == 0)
  87.             return 0;
  88.         for (i = 0; i < numRead/2; i++) {
  89.             buff[i] = fubb[i*2];
  90.                     }
  91.         WriteFile (ofh, &buff, numRead/2, &numWritten, 0);
  92.         }
  93.  
  94.     return 0;
  95. }
  96.  
  97.